<script setup>
import ShortPolling from './components/ShortPolling.vue'
import LongPolling from './components/LongPolling.vue'
import SSE from './components/SSE.vue'
import WebSocket from './components/WebSocket.vue'
</script>

<template>
  <div class="app">
    <header class="header">
      <h1>Vue3 + Nest.js 实时通信项目</h1>
      <p class="subtitle">四种方案（短轮询 / 长轮询 / SSE / WebSocket）全解析</p>
    </header>
    
    <div class="grid">
      <div class="card">
        <div class="card-header">
          <h2>短轮询 (Short Polling)</h2>
          <span class="badge">简单</span>
        </div>
        <p class="description">客户端定期发送 HTTP 请求，获取服务器最新数据</p>
        <ShortPolling />
      </div>
      
      <div class="card">
        <div class="card-header">
          <h2>长轮询 (Long Polling)</h2>
          <span class="badge">优化</span>
        </div>
        <p class="description">服务器保持连接不返回，直到有新数据或超时</p>
        <LongPolling />
      </div>
      
      <div class="card">
        <div class="card-header">
          <h2>SSE (Server-Sent Events)</h2>
          <span class="badge">单向</span>
        </div>
        <p class="description">服务器单向推送数据，客户端被动接收</p>
        <SSE />
      </div>
      
      <div class="card">
        <div class="card-header">
          <h2>WebSocket</h2>
          <span class="badge">全双工</span>
        </div>
        <p class="description">全双工实时通信，支持双向数据传输</p>
        <WebSocket />
      </div>
    </div>
    
    <footer class="footer">
      <p>基于开源项目 <a href="https://gitee.com/xcxsj/realtime.git" target="_blank">墨竹 /realtime</a></p>
    </footer>
  </div>
</template>

<style>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
}

.app {
  margin: 0 auto;
  padding: 20px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  text-align: center;
  margin-bottom: 40px;
  color: white;
}

.header h1 {
  font-size: 2.5rem;
  margin-bottom: 10px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.subtitle {
  font-size: 1.2rem;
  opacity: 0.9;
  font-weight: 300;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 30px;
  flex: 1;
}

.card {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card:hover {
  transform: translateY(-5px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.card h2 {
  color: #2c3e50;
  font-size: 1.4rem;
  font-weight: 600;
}

.badge {
  background: linear-gradient(45deg, #42b983, #4fc08d);
  color: white;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
}

.description {
  color: #666;
  margin-bottom: 20px;
  font-size: 0.9rem;
  line-height: 1.5;
}

.footer {
  text-align: center;
  margin-top: 40px;
  color: rgba(255, 255, 255, 0.8);
}

.footer a {
  color: #42b983;
  text-decoration: none;
  font-weight: 500;
}

.footer a:hover {
  text-decoration: underline;
}

@media (max-width: 768px) {
  .grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }
  
  .header h1 {
    font-size: 2rem;
  }
  
  .subtitle {
    font-size: 1rem;
  }
}
</style>
